import type { RentItemType, EditEnterpriseParams, EnterpriseDetailType, EnterpriseListData, EnterpriseListParams, EnterpriseParams, Industry, RentBuilding, RentParams, EnterpriseWatch } from '@/types/enterprise'
import service, { myGet, myPost, myRequest } from '@/utils/reuqest'

// 获取企业列表
export const getEnterpriseListAPI = (params: EnterpriseListParams) => {
  return myGet<EnterpriseListData>('/park/enterprise', params)
}

// 获取行业列表
export const getIndustryListAPI = () => {
  return myGet<Industry[]>('/park/industry')
}

// 添加企业
export const createEnterpriseAPI = (data: EnterpriseParams) =>{
  return myPost('/park/enterprise', data)
}

// 查看企业详情
export const getEnterpriseAPI = (id: string) => {
  return myGet<EnterpriseDetailType>(`/park/enterprise/${id}`)
}

// 编辑企业
export const editEnterpriseAPI = (data: EditEnterpriseParams) => {
  return myRequest({
    url: '/park/enterprise',
    method: 'PUT',
    data
  })
}

// 删除企业
export const deleteEnterpriseAPI = (id: string) => {
  return myRequest({
    url: `/park/enterprise/${id}`,
    method: 'DELETE'
  })
}

// 获取空置中楼宇列表（未租赁）
export const getRentBuildListAPI = () => {
  return myGet<RentBuilding[]>('/park/rent/building')
}

// 给当前企业添加合同
export const createRentAPI = (data: RentParams) => {
  return myPost('/park/enterprise/rent', data)
}

// 获取企业下合同列表
export const getRentListAPI = (id: number) => {
  return myGet<RentItemType[]>(`/park/enterprise/rent/${id}`)
}

// 退租合同
export const outRentAPI = (rentId: string)=> {
  return myRequest({
    url: `/park/enterprise/rent/${rentId}`,
    method: 'PUT'
  })
}

// 删除合同
export const deleteRentAPI = (rentId: string)=> {
  return myRequest({
    url: `/park/enterprise/rent/${rentId}`,
    method: 'DELETE'
  })
}

// 获取企业详情
export const getEnterpriseDetailAPI = (id: string) => {
  return myGet<EnterpriseWatch>(`/park/enterprise/${id}`)
}

// 下载合同文件
export const downloadContract = (id: string) => {
  // 第二个范型参数为 Blob
  return service<null, Blob>({
    method: 'GET',
    url: `/download/${id}`,
    responseType: 'blob' // 把二进制数据流转换成 blob 对象，用于下载
  })
}